package com.gy.api.pc.content.controller;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.PageInfo;
import com.gy.api.base.ApiIndex;
import com.gy.api.base.IDsEntity;
import com.gy.api.base.R;
import com.gy.api.base.RestPage;
import com.gy.api.pc.content.domain.vo.*;
import com.gy.api.pc.content.service.IBannerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.rmi.ServerException;
import java.util.List;


@Controller
@RequestMapping("/system/banner")
@Api( tags = ApiIndex.BannerController)
public class BannerController{

    @Autowired
    private IBannerService bannerService;


    @GetMapping("/typeList")
    @ApiOperation(value = "banner类型查询接口")
    @ResponseBody
    public R<List<BannerVO>> typeList(BannerSelectListDto bannerList) {
        List<BannerVO> list = bannerService.selectBannerTypeList(bannerList);
        return new R(list);
    }


    @GetMapping("/list")
    @ApiOperation(value = "banner列表")
    @ResponseBody
    public R<RestPage<List<BannerVO>>> list(@ApiParam(value = "查询参数") @ModelAttribute  BannerSelectListPageDto bannerList) {
        List<BannerVO> list = bannerService.selectBannerPageList(bannerList);
        RestPage restPage = new RestPage( new PageInfo(list),list);
        return new R(restPage);
    }
//
//    /**
//     * 导出banner列表
//     */
//    @Log(title = "banner", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    @ResponseBody
//    public AjaxResult export(Banner banner) {
//        List<Banner> list = bannerService.selectBannerList(banner);
//        ExcelUtil<Banner> util = new ExcelUtil<Banner>(Banner.class);
//        return util.exportExcel(list, "banner数据");
//    }

    @PostMapping("/add")
    @ApiOperation(value = "添加banner")
    @ResponseBody
    public R addSave(@RequestBody BannerAddVo addDto) throws ServerException {
        bannerService.addSave(addDto);
        return new R();
    }


    @PostMapping("/edit")
    @ApiOperation(value = "修改banner")
    @ResponseBody
    public R editSave(@RequestBody BannerUpdateVo updateDto) throws ServerException {
        bannerService.editSave(updateDto);
        return new R();
    }

    @PostMapping("/editState")
    @ApiOperation(value = "是否置顶")
    @ResponseBody
    public R editState(@RequestBody BannerStateUpdateDto updateDto) throws ServerException {
        bannerService.editState(updateDto);
        return new R();
    }

    @PostMapping("/remove")
    @ApiOperation(value = "删除banner")
    @ResponseBody
    public R remove(@RequestBody IDsEntity iDsEntity) {
        bannerService.deleteBannerByBannerIds(iDsEntity.getIds());
        return new R();
    }
}
